package com.peng.mybatis.type;

import lombok.AllArgsConstructor;

import java.sql.Types;
import java.util.Arrays;

@AllArgsConstructor
public enum JdbcType {

    INTEGER(Types.INTEGER),
    FLOAT(Types.FLOAT),
    DOUBLE(Types.DOUBLE),
    DECIMAL(Types.DECIMAL),
    VARCHAR(Types.VARCHAR),
    TIMESTAMP(Types.TIMESTAMP),
    ;

    public final int TYPE_CODE;

    public static JdbcType forCode(int code) {
        return Arrays.stream(values())
                .filter(v -> v.TYPE_CODE == code)
                .findAny()
                .orElse(null);
    }

}
